<?php

class TBMPhanCongHDXD extends BaseController {

    public function index() {
            $idhknk = HomeController::getIdHknkMax();
            $idbm = Session::get('infor.idbm')[0];
            $de_tais = $this->getDeTaiCanPhanCong($idbm, $idhknk);
        return View::make('truongbomon.hdxd')->with('title', 'Phân công hội đồng xét duyệt')->with('de_tais',$de_tais);
    }

    public function getDeTaiCanPhanCong($idbm, $idhknk) {
        $de_tais = DB::select(DB::raw("call get_ds_de_tai_can_phan_cong(" . $idhknk . "," . $idbm . ");"));
        return $de_tais;
    }

    public function showPhanCong() {
        $id_de_tai = Input::get('txtIdDeTai');
         $de_tai = DB::select(DB::raw("call get_chi_tiet_hdxd(" .$id_de_tai. ");"));
        return View::make('truongbomon.chitietphancong')->with('title', 'Chi tiết phân công hội đồng')->with('de_tai', $de_tai);
    }
    public function store()
    {   
        $mshd = Input::get('msHoiDong');
        $iddetai = Input::get('idDeTaiLV');
        $idchutich = Input::get('chuTich');
        $iduyvien = Input::get('uyVien');
        $idthuky = Input::get('thuKiLV');
        $thoigianxetduyet = date('Y-m-d H:i:s',strtotime(Input::get('ngayXetDuyet')));
        $result = DB::select(DB::raw("call insert_hdxd('".$mshd."'," .$iddetai. ",".$idchutich.",".$iduyvien.",".$idthuky.",'".$thoigianxetduyet."');"));
        return Redirect::to('/tbm/6/hdxd');
    }
    
    public function getMaSoHD() {
        $id_next = HoiDongXetDuyet::max('id') + 1;
        $ma_so_next = "HD000"; //HDXXXX
        $ma_so_next = substr($ma_so_next, 0, 5 - strlen($id_next)) . $id_next;
        return $ma_so_next;
    }

    public function getDSCanBo($iddt,$idbm) {
        
        $can_bos = DB::select(DB::raw("call get_ds_can_bo_hoi_dong(".$idbm."," .$iddt. ",0);"));
        return $can_bos;
    }

    public function getCanBoHD($iddt,$idbm) {
        $can_bo = DB::select(DB::raw("call get_ds_can_bo_hoi_dong(".$idbm."," .$iddt. ",1);"));
        return $can_bo;
    }

}
